#!/bin/sh

# Run wrapper-script to be called from 'testcase_run.sh'.
#
# This script is meant to simplify writing interactive problems where
# the contestants' solution bi-directionally communicates with a jury
# program, e.g. while playing a two player game.
#
# Usage: $0 <testin> <progout> <program>...
#
# <testin>    File containing test-input.
# <progout>   File where to write solution output.
# <program>   Command and options of the program to be run.
#
# A jury-written program called 'runjury' should be available; this
# program will normally be copied from 'runjury_<specialrun>' by
# testcase_run.sh. This program should communicate with the
# contestants' program to provide input and read output via
# stdin/stdout. This wrapper script handles the setup of
# bi-directional pipes. The jury program should accept the following
# calling syntax:
#
#    runjury <testin> <progout>
#
# The jury program should exit with exitcode zero unless an unexpected
# failure occurred (malformed contestant's program output should be
# handled by the jury program), and write output to <program.out> such
# that that data can later be used to verify correctness of the
# contestants' solution.

TESTIN="$1";  shift
PROGOUT="$1"; shift

MYDIR=$(dirname $0)

# Run the program while redirecting its stdin/stdout to 'runjury' via
# 'runpipe'. Note that "$@" expands to separate, quoted arguments.
exec ../dj-bin/runpipe ${DEBUG:+-v} "$MYDIR/runjury" "$TESTIN" "$PROGOUT" = "$@"
